Conversation
Melevir
left a comment
There was a problem hiding this comment.
Стало сильно лучше, но ещё не приехали.
С аннотациями типов надо оч много внимательности, мб из-за того что ты по вечерам/ночам сидишь – часто упускаешь какую-нибудь скобку или типа того. Просто предположение.
| if __name__ == "__main__": | ||
| assert compose_full_name(first_name="John", last_name="Doe", middle_name=None) == "Doe John" | ||
| assert compose_full_name(first_name="Ilya", last_name="Lebedev", middle_name="Alexeyevich") == "Lebedev Ilya Alexeyevich" | ||
| assert compose_full_name(first_name = "John", last_name = "Doe", middle_name = None) == "Doe John" |
There was a problem hiding this comment.
Не, когда у функции указываешь именованые аргументы, пробелы вокруг равно не нужны. Они нужны когда равно – это присваивание значения переменной.
|
|
||
| def is_point_in_square(point: ___, left_upper_corner: ___, right_bottom_corner: ___) -> ___: | ||
|
|
||
| def is_point_in_square(point: tuple[int, int], left_upper_corner: tuple[int, int], right_bottom_corner: tuple[int]) -> bool: |
There was a problem hiding this comment.
right_bottom_corner тоже из двух элементов состоит :)
|
|
||
|
|
||
| def get_transaction_amount(transaction_id: ___, transactions_amounts_map: ___) -> ___: | ||
| def get_transaction_amount(transaction_id:int, transactions_amounts_map: dict[int, decimal.decimal]) -> dict[int, decimal.decimal] | None: |
There was a problem hiding this comment.
decimal.Decimal. Заглавную букву потеряла
|
|
||
|
|
||
| def is_name_male(name: ___, name_gender_map: ___) -> ___: | ||
| def is_name_male(name: str, name_gender_map: dict[str, bool]) -> bool: |
There was a problem hiding this comment.
Возвращаемый тип не совсем точный
|
|
||
|
|
||
| def parse_receipt(raw_receipt: ___) -> ___: | ||
| def parse_receipt(raw_receipt: str) -> tuple[int, datetime.date, list[tuple[str, int, float]]]: |
There was a problem hiding this comment.
В тупле в последнем элементе не флоат
| class User(TypedDict): | ||
| "name": str | ||
| "age": int | ||
| "transactions_sums": list[int] |
There was a problem hiding this comment.
Тут кавычки лишние, правильно как в датаклассах.
| #def calculate_total_spent_for_user(user: TypedDict('User', 'name' = str, 'age' = int, 'transactions_sums' = list[int])) -> int: | ||
| #def calculate_total_spent_for_user(user: TypedDict('User', {'name': str, 'age': int, 'transactions_sums': list[int]})) -> int: | ||
|
|
||
| # пока на основе документации понимаю, что оба варианта верны, и именно в таком виде, без квадратных скобок No newline at end of file |
There was a problem hiding this comment.
Синтаксически это может и верно, но в реальной жизни если и приходится использвоать тайпеддикт (редко), то пригождается тот способ, которым ты воспользовалась: ты отдельно определяешь тайпдикт как класс, а потом указываешь его в аннотации.
| def create_user(user_name: ___, user_age: ___, after_created: ___) -> ___: | ||
| pass | ||
|
|
||
| def create_user(user_name: str, user_age: int, after_created: function) -> None: |
There was a problem hiding this comment.
Тут пока неправильно. Посмотри, какие типы есть в модуле typing, может найдёшь чего :)
No description provided.